<?php
/**
 * Created by PhpStorm.
 * User: edmmss
 * Date: 2018/12/24
 * Time: 10:19
 */

namespace app\modules\memento;


class Ticket
{
    private $_currentState;

    public function __construct()
    {
        $this->_currentState = new State(State::STATE_CREATED);
    }

    public function open()
    {
        $this->_currentState = new State(State::STATE_OPENED);
    }

    public function assign()
    {
        $this->_currentState = new State(State::STATE_ASSIGNED);
    }

    public function close()
    {
        $this->_currentState = new State(State::STATE_CLOSED);
    }

    public function saveToMemento(): Memento
    {
        return new Memento(clone $this->_currentState);
    }

    public function restoreFromMemento(Memento $memento)
    {
        $this->_currentState = $memento->getState();
    }

    public function getState(): State
    {
        return $this->_currentState;
    }
}